package com.sunseagear.wind.modules.sys.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sunseagear.common.base.mvc.entity.DataEntity;
import com.sunseagear.common.utils.StringUtils;
import com.sunseagear.wind.common.utils.excel.annotation.ExcelField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @version V1.0
 * @Title 用户实体
 * @Description:
 * @date 2016-12-03 21:31:50
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("sys_user")
@Getter
@Setter
@SuppressWarnings("serial")
public class User extends DataEntity<Long> {

    /**
     * 是否锁定（1：正常；-1：删除；0：锁定；）
     */

    public static final String STATUS_DELETE = "-1";
    public static final String STATUS_LOCKED = "0";
    public static final String STATUS_NORMAL = "1";


    /**
     * id
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;
    // 姓名
    @ExcelField(title = "用户名", sort = 1)
    private String username;
    // 用户名
    @ExcelField(title = "姓名",sort = 2)
    private String realname;
    // 头像
    private String portrait;
    // 密码
    private String password;
    // 邮件
    @ExcelField(title = "邮件", sort = 3)
    private String email;
    // 联系电话
    @ExcelField(title = "联系电话", sort = 4)
    private String phone;

    private String tenantId; //租户ID

    @TableField(value = "organization_id")
    private Long organizationId;

    @TableField(exist = false)
    private Organization organization;
    /**
     * 系统用户的状态
     */
    private String status = STATUS_NORMAL;

    @TableField(exist = false)
    List<Role> roles;  //角色数据
    @TableField(exist = false)
    List<String> roleIdList;

    public String findRoleIds() {
        List<Long> roleIds = new ArrayList<>();
        roles.forEach(item -> roleIds.add(item.getId()));
        return StringUtils.join(roleIds, ",");
    }
}
